import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'dart:convert' as convert;

import '../../model/user_info.dart';
import '../../views/base_page/base_component_demo.dart';
import '../../views/home_page/home_page.dart';
import '../../views/listview_page/listview_demo.dart';
import '../../views/other_page/not_found.dart';
import '../../views/tabbar_page/tab_bar_demo.dart';
import '../../views/webview_page/webView_demo.dart';
import '../../views/wx_page/wx_share_page.dart';

var notFoundHandler =
Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
  return NotFoundPage();
});


// 根目录--菜单页
var rootHandler =
Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
  return const HomePage();
});

// 根目录--listview列表
var ListViewHandler =
Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
  return const ListViewDemo();
});

var TabBarDemoHandler =
Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
  return const TabBarDemo();
});

var BaseComponentDemoHander =
Handler(handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
  return const BaseComponentDemo();
});

// 网页加载 - 示例：传多个字符串参数
var webViewHandler = Handler(handlerFunc: (BuildContext ? context, Map<String, dynamic> params) {
  // params内容为  {title: [我是标题哈哈哈], url: [https://www.baidu.com/]}
  String title = params['title']?.first;
  String url = params['url']?.first;
  return WebViewUrlPage(
    title: title,
    url: url,
  );
});

// 示例：传多个model参数
var wxSharePayHandler =
Handler(handlerFunc: (BuildContext ? context, Map<String, dynamic> params) {
//  print('params: $params');
//  String model = params['userInfoModel']?.first;
//  print('model: $model');
//  // model: {name: yuanzhiying, age: 30, height: 1.78, weight: 74.0}
//  Map<String, dynamic> jsonMap = convert.jsonDecode(model);
//  print('jsonMap: $jsonMap');
//  UserInfoModel _model = UserInfoModel.fromJson(jsonMap);

  UserInfoModel _model1 =
  UserInfoModel.fromJson(convert.jsonDecode(params['userInfoModel'][0]));
  UserInfoModel _model2 =
  UserInfoModel.fromJson(convert.jsonDecode(params['userInfoModel2'][0]));

  return WxSharePage(
    userInfoModel: _model1,
    userInfoModel2: _model2,
  );
});